const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      rules: {
       
      },
      form: {
        Traceability_Batch_SerialNumber:'',
        Traceability_Base_SerialNumber:'',
        Produce_Date:'',
        Article_SerialNumber:'',
        Contacts:'',
        Contact_Phone:'',
        Video_URL:'/muer.mp4',
        Enterprise_Info_SerialNumber:$.cookie("enterprise"),
      },
      loading: false,
      traceabilitybase_info:[],
      article_info:[]
    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData(){
      const _this = this 
      $.ajax({
        url: DomainName + '/getInquiryAction',
        type: 'POST',
        data: {
          Data:'article_info',
          token:$.cookie('token')
        },
        success: function (res) {
          _this.article_info = res
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/getInquiryAction',
        type: 'POST',
        data: {
          Data:'traceabilitybase_info',
          token:$.cookie('token')
        },
        success: function (res) {
          _this.traceabilitybase_info = res
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: DomainName + '/getAddAction',
            type: 'POST',
            data: {
              Data:JSON.stringify({traceability_batch:[_this.form]}),
              token:$.cookie('token')
            },
            success: function (res) {
              console.log('提交结果', res)
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
})